package com.dbh.design.factory.simple;

import com.dbh.design.factory.entity.DellMouse;
import com.dbh.design.factory.entity.HpMouse;
import com.dbh.design.factory.entity.LenovoMouse;
import com.dbh.design.factory.entity.Mouse;

/**
 * Mouse
 * 鼠标创建工厂
 *
 *  简单工厂
 *      优点：可以对创建的对象进行“加工”，对客户端隐藏相关细节
 *      缺点：因创建逻辑负载或创建对象过多造成代码臃肿
 *      缺点：新增、删除子类均会违反开闭原则
 *
 * @author dongbanghui
 * @date 2021/07/23
 */
public class MouseFactory {

    /**
     * 创建鼠标对象
     * @param type
     * @return
     */
    public static Mouse createMouse(int type) {
        switch (type) {
            case 0:
                return new DellMouse();
            case 1:
                return new HpMouse();
            case 2:
                return new LenovoMouse();
            default:
                return new DellMouse();
        }
    }

    public static void main(String[] args) {
        Mouse mouse = MouseFactory.createMouse(0);
        mouse.sayHi();

    }
}
